package io.wdb.common.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateFormatUtil {

	public static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss" ;
	
	public static final String DATE_PATTERN = "yyyy-MM-dd";
	
	public static final String TIME_PATTERN = "HH:mm:ss" ;
	
	public static final String DATE_PATTERN2 = "yyyy年MM月dd日";
	
	public final static String DATE_PATTERN_LEAN="yyyy/MM/dd";
	
	public final static String DATE_PATTERN_LEN_HOUR = "yyyy/MM/dd/HH";
	
	public final static String TIME_PATTERN_NO_COLON = "HHmm";
	
	public static String formateDateToString(Date date,String pattern) {
		DateFormat df = null;
		if(pattern==null) {
			df = new SimpleDateFormat(DATETIME_PATTERN);
		}else {
			df = new SimpleDateFormat(pattern);
		}
		return df.format(date);
	}
	
	public static Date parseDatePattern(String date,String pattern) {
		DateFormat df = new SimpleDateFormat(DATE_PATTERN);
		if(pattern!=null&&!pattern.trim().equals("")) {
			df = new SimpleDateFormat(pattern);
		}
		Date d = null;
		try {
			d = df.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return d;
	}
	public static Date parseDate(String date) {
		DateFormat df = new SimpleDateFormat(DATE_PATTERN);
		Date d = null;
		try {
			d = df.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return d;
	}
	
	public static Date parseDateTime(String datetime) {
		DateFormat df = new SimpleDateFormat(DATETIME_PATTERN);
		Date d = null;
		try {
			d = df.parse(datetime);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return d;
	}
	
	public static Date parseTime(String time) {
		DateFormat df = new SimpleDateFormat(TIME_PATTERN);
		Date d = null;
		try {
			d = df.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return d;
	}
	public static String formatDate(Date date,String pattern) {
		DateFormat df = new SimpleDateFormat(pattern);
		return df.format(date);
	}
	public static String formatDate(Date date) {
		DateFormat df = new SimpleDateFormat(DATE_PATTERN);
		return df.format(date);
	}
	
	public static String formatDate2(Date date) {
		DateFormat df = new SimpleDateFormat(DATE_PATTERN2);
		return df.format(date);
	}
	public static String formatTime(Date date) {
		DateFormat df = new SimpleDateFormat(TIME_PATTERN);
		return df.format(date);
	}
	
	public static String formatDateTime(Date date) {
		DateFormat df = new SimpleDateFormat(DATETIME_PATTERN);
		return df.format(date);
	}
	
}
